<?php 
echo $javascript->link('jquery-1.4.2');
echo $html->css ( 'tab' );
echo $html->css ( 'style' );
echo $html->css ( 'schedules' );
?>

<script type="text/javascript">
function getDaysInMonth(year,month)
{
 month = parseInt(month,10)+1;
 var temp = new Date(year+"/"+month+"/0");
 return temp.getDate();
}
function listdates(nowYear,nowMonth)
{
	var days=getDaysInMonth(nowYear,nowMonth);
	$.ajax({
        type: "post",
        url: "<?php echo ROOT_WEB_PATH; ?>/schedules/getmonthSchedule",
         data: {
        	year:nowYear,
        	month:nowMonth,
        	days:days
        },
         dataType:"json",
         success: function(data) {
        	 $("td").text("");
     		var so=1;
     		if(nowMonth<10)
     		{
     			nowMonth="0"+nowMonth;
         	}
     		for(i=1;i<=days;i++)
     		{
         		var j=i;
         		if(i<10)
         		{
             		j="0"+i;
             	}
     			var dd=nowYear+"/"+nowMonth+"/"+j;
     			var da=new Date(dd);
     			var dy=da.getDay();
     			var ind=(so-1)*7+dy;
     			var context="<a href='#' style='color:#747474;margin:-24px 0px 0px 0px;position:relative;' class='ind"+i+"'>"+i+"</a>  <a href='#' style='margin:10px;position:relative;' class='add"+i+"'><img style='border:0px;' src='<?php echo ROOT_WEB_PATH; ?>/app/webroot/img/add_small.gif'></img></a>";
     			var co=data.cc;
     			if(co>0)
     			{
     			$.each(data.rows,function(a,row){
					var startday=row.startDate;
					var endday=row.endDate;
					var tosd=nowYear+"-"+nowMonth+"-"+j+" 00:00:00";
					var toed=nowYear+"-"+nowMonth+"-"+j+" 23:59:59";
					if(startday<=toed&&endday>=tosd)
					{
						var id=row.id;
						var title=row.title;
						var app="<a href='#' style='background-color:#fdfbdb;border:1px solid #e1dea6;color:#6e9bf4;margin:2px;'; class='app"+id+"'>"+title+"</a>";
						context=context+app;
					}
     			 });
     			}
     			$("td:eq("+ind+")").html(context);
     			if (dy==6)
     			{
     				so++;
     			}
     		}

     		$("a[class^='ind']").bind("click",function(){
     			var href="<?php echo ROOT_WEB_PATH; ?>/schedules/daySchedule";
     			var cDay=$(this).attr("class").substring(3);
     			op(href,cDay);
     		});

     		$("a[class^='add']").bind("click",function(){
     			var href="<?php echo ROOT_WEB_PATH; ?>/schedules/addinit";
     			var cDay=$(this).attr("class").substring(3);
     			op(href,cDay);
     		});

     		$("a[class^='app']").bind("click",function(){
     			var id=$(this).attr("class").substring(3);
     			var href="<?php echo ROOT_WEB_PATH; ?>/schedules/edit/"+id;
     			window.open(href);
     		});

     		
		 },
         error: function(data) {
		         alert("获取数据异常");
			}
     });
}
function op(href,cDay)
{
	var cd=$(".nedate").val();
	var s=cd.split("/");
	var cYear=s[0];
	var cMonth=s[1];
	if(cMonth<10)
	{
		cMonth="0"+cMonth;
	}
	if(cDay<10)
	{
		cDay="0"+cDay;
	}
	var da=cYear+"-"+cMonth+"-"+cDay;
	var url=href+"/"+da;
	window.open(url);
}
$(function(){
var d=new Date();
var nowYear=d.getFullYear();
var nowMonth=d.getMonth()+1;
var nowDate=d.getDate();
var nedate=nowYear+"/"+nowMonth;
$(".nedate").val(nedate);
var ndm=nowYear+"年"+nowMonth+"月";
$(".nev").text(ndm);
var pretext=0;
var nextext=0;
if(nowMonth==1)
{
	pretext=12;
}
else
{
	pretext=nowMonth-1;
}
if(nowMonth==12)
{
	nextext=1;
}
else
{
	nextext=nowMonth+1;
}
$(".prev").text(pretext+"月");
$(".next").text(nextext+"月");
listdates(nowYear,nowMonth);


$(".prev").click(function(){
	var cd=$(".nedate").val();
	var s=cd.split("/");
	var cYear=s[0];
	var cMonth=s[1];
	var neYear=0;
	var neMonth=0;
	if(cMonth==1)
	{
		neYear=cYear-1;
		neMonth=12;
	}
	else
	{
		neYear=cYear;
		neMonth=cMonth-1;
	}
	var ndm=neYear+"年"+neMonth+"月";
	$(".nev").text(ndm);
	var nedate=neYear+"/"+neMonth;
	$(".nedate").val(nedate);
	var pretext=0;
	var nextext=0;
	if(neMonth==1)
	{
		pretext=12;
	}
	else
	{
		pretext=neMonth-1;
	}
	if(neMonth==12)
	{
		nextext=1;
	}
	else
	{
		nextext=neMonth-0+1;
	}
	$(".prev").text(pretext+"月");
	$(".next").text(nextext+"月");
	listdates(neYear,neMonth);
});



$(".next").click(function(){
	var cd=$(".nedate").val();
	var s=cd.split("/");
	var cYear=s[0];
	var cMonth=s[1];
	var neYear=0;
	var neMonth=0;
	if(cMonth==12)
	{
		neYear=cYear-0+1;
		neMonth=1;
	}
	else
	{
		neYear=cYear;
		neMonth=cMonth-0+1;
	}
	var ndm=neYear+"年"+neMonth+"月";
	$(".nev").text(ndm);
	var nedate=neYear+"/"+neMonth;
	$(".nedate").val(nedate);
	var pretext=0;
	var nextext=0;
	if(neMonth==1)
	{
		pretext=12;
	}
	else
	{
		pretext=neMonth-1;
	}
	if(neMonth==12)
	{
		nextext=1;
	}
	else
	{
		nextext=neMonth-0+1;
	}
	$(".prev").text(pretext+"月");
	$(".next").text(nextext+"月");
	listdates(neYear,neMonth);	
});
});


</script>

<!--                                          by dailei-->

<input type="hidden" class="nedate"></input>
<div class="title">
<ul>
	<li class="previmg"><a href="#" class="prev"></a></li>
	<li class="nextimg"><a href="#" class="next"></a> </li>
	<li class="nevimg"><a class="nev"></a> </li>
	<li class="datebutton"><a href="<?php echo ROOT_WEB_PATH; ?>/schedules/addinit/" target="_blank"><?php echo $html->image('add_small.gif', 
		 							array('title'=>'新增日程','border'=>'0' )); ?>&nbsp;新增日程</a></li>			 
	<li class="datebutton"><a href="<?php echo ROOT_WEB_PATH; ?>/schedules/weekSchedule/"><?php echo $html->image('dateicon.gif', 
		 							array('title'=>'周日程','border'=>'0' )); ?>&nbsp;周日程</a></li>
	<li class="datebutton">
		<a href="<?php echo ROOT_WEB_PATH; ?>/schedulestyles/index/" target="_blank">
							<?php echo $html->image('date_type.gif', 
		 							array('title'=>'类型管理','border'=>'0' )); ?>&nbsp;类型管理</a></li>
	<li class="datebutton">
		<a href="<?php echo ROOT_WEB_PATH; ?>/importances/index/" target="_blank">
							<?php echo $html->image('date_important.gif', 
		 							array('title'=>'重要性管理','border'=>'0' )); ?>&nbsp;重要性管理</a></li>
</ul>
</div>
<table class="datepicker" cellspacing="0" cellpadding="0">
<tr>
<th>星期日</th>
<th>星期一</th>
<th>星期二</th>
<th>星期三</th>
<th>星期四</th>
<th>星期五</th>
<th>星期六</th>
</tr>
<tr>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>

</table>

